package com.example.demolearn.utils;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class PingTest {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("XF_Sanshui.1_13_1460","172.16.35.207");
        map.put("XF_Sanshui.2_1_4000","172.16.34.22");
        map.put("XF_Sanshui.3_4_1800","172.16.34.26");
        map.put("XF_Sanshui.3_9_1460","172.16.34.10");
        map.put("XF_Sanshui.5_10_1460","172.16.34.18");
        map.put("XF_Jingmi.6300","10.24.136.200");
        Iterator<Map.Entry<String, String>> ips = map.entrySet().iterator();
        while (ips.hasNext()) {
            Socket socket = new Socket();

            Map.Entry<String, String> entry = ips.next();
            try {
                socket.connect(new InetSocketAddress(entry.getValue(),2020),1000);
            } catch (IOException ioException) {
                System.out.println(entry.getKey() + "产线，ip:" + entry.getValue() + " ping不通");
            }finally {
                try {
                    socket.close();
                } catch (IOException ioException) {
                    System.out.println("关闭失败");
                }
            }

        }

    }
}
